package com.chat.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chat.domain.pojo.Message;
import com.chat.mapper.MessageMapper;
import com.chat.service.MessageService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wb
 * @since 2025-06-06
 */

@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements MessageService {

    @Override
    public List<Message> getMessagesByChatId(String chatId) {
        return baseMapper.selectMessagesByChatId(chatId);
    }

    @Override
    public Boolean updateReadStatus(String chatId, Integer userId) {
        LambdaQueryWrapper<Message> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Message::getChatId, chatId);
        lqw.notIn(Message::getSendId, userId);

        Message message = new Message();
        message.setIsRead(1);

        return super.update(message, lqw);
    }
}
